﻿using AutoMapper;
using mozhi.smarterp.Finance.Accounts;
using System;
using System.Collections.Generic;
using System.Text;

namespace mozhi.smarterp.Finance.MapperConverters
{
    public class AccountBalancesToDtoConverter : ITypeConverter<List<AccountBalance>, AccountBalanceDto>
    {
        public AccountBalanceDto Convert(List<AccountBalance> source, AccountBalanceDto destination, ResolutionContext context)
        {
            destination = new AccountBalanceDto() { Items = new List<AccountBalanceItemDto>() };

            destination.AccountId = source[0].AccountId;

            foreach (var item in source)
            {
                destination.Items.Add(new AccountBalanceItemDto()
                {
                    Period = item.Period,
                    CurrencyId = item.CurrencyId,
                    OpeningAmount = item.OpeningAmount,
                    OpeningAmountFr = item.OpeningAmountFr,
                    DebitAmount = item.DebitAmount,
                    DebitAmountFr = item.DebitAmountFr,
                    CreditAmount = item.CreditAmount,
                    CreditAmountFr = item.CreditAmountFr,
                    CurrentYearDebitAmount = item.CurrentYearDebitAmount,
                    CurrentYearDebitAmountFr = item.CurrentYearDebitAmountFr,
                    CurrentYearCreditAmount = item.CurrentYearCreditAmount,
                    CurrentYearCreditAmountFr = item.CurrentYearCreditAmountFr,
                    Direction = item.Direction,
                    DimensionGroupValueId = item.DimensionGroupValueId,
                    DimensionGroupValueItems = new List<Basedatas.DimensionGroupValueItemDto>()
                });
            }

            return destination;
        }
    }
}
